// debounce
function debounce(fn, delay){
  let timer
  delay = delay || 1000

  return function() {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.call(this, arguments)
      timer = null
    }, delay)
  }
}
